package com.sl.au.service.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.AccountsReceivablePlan;
import com.sl.au.entity.ScadaBasePoint;
import com.sl.au.entity.scadaModelPointRelation;
import com.sl.au.repository.AccountsReceivablePlanRepository;
import com.sl.au.service.AccountsReceivablePlanService;
import com.sl.au.service.QueryService;

@Service("AccountsReceivablePlanService")
@Transactional
public class AccountsReceivablePlanServiceImpl  extends BaseServiceImpl implements AccountsReceivablePlanService {

	@Autowired
	AccountsReceivablePlanRepository accountsReceivablePlanRepository;
	
	@Autowired
	QueryService queryService;
	@Override
	public AccountsReceivablePlanRepository getRepository() {
		// TODO Auto-generated method stub
		return this.accountsReceivablePlanRepository;
	}
	@Override
	public List<AccountsReceivablePlan> findByIds(String ids) {
		StringBuilder hql = buildCombinedQueryHql("AccountsReceivablePlan", "id", ids, "createTime", "desc");
		Query query=queryService.createQueryHql(hql.toString());
		System.out.println(hql.toString());
		@SuppressWarnings("unchecked")
		List<AccountsReceivablePlan> AccountsReceivablePlans = query.getResultList();
		return AccountsReceivablePlans;
	}
	
	public StringBuilder buildCombinedQueryHql(String entityName, String selectedProperty, String ids, String orderName, String dir){
		StringBuilder hql = new StringBuilder();
		hql.append("select e from " + entityName + " e where e.id is not null ");
		hql.append(" and e." + selectedProperty + " in (" + ids + ")");
		hql.append(" order by " + orderName + " " + dir);
		return hql;
	}

}
